/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.recursos.entidades;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author MARA
 */
@Entity
@Table(name = "RECURSO")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Recurso.findAll", query = "SELECT r FROM Recurso r"),
    @NamedQuery(name = "Recurso.findByIdRecurso", query = "SELECT r FROM Recurso r WHERE r.idRecurso = :idRecurso"),
    @NamedQuery(name = "Recurso.findByDescRecurso", query = "SELECT r FROM Recurso r WHERE r.descRecurso = :descRecurso"),
    @NamedQuery(name = "Recurso.findByNombre", query = "SELECT r FROM Recurso r INNER JOIN r.idEstado ie WHERE r.descRecurso LIKE :descRecurso and ie.idEstado= :idEstado "),
    @NamedQuery(name = "Recurso.findByEstado", query = "SELECT r FROM Recurso r INNER JOIN r.idEstado e WHERE e.idEstado = :idEstado"),
    @NamedQuery(name = "Recurso.findByTipo", query = "SELECT r FROM Recurso r INNER JOIN r.idTipo t WHERE t.idTipoRecurso = :idTipoRecurso"),
    @NamedQuery(name = "Recurso.findByVersion", query = "SELECT r FROM Recurso r WHERE r.version = :version")})
public class Recurso implements Serializable {
    private static final long serialVersionUID = 1L;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Id
    @Basic(optional = false)
    @NotNull
    @Column(name = "ID_RECURSO")
    private BigDecimal idRecurso;
    @Size(max = 60)
    @Column(name = "DESC_RECURSO")
    private String descRecurso;
    @Size(max = 60)
    @Column(name = "VERSION")
    @Version
    private Integer version;
    @OneToMany(mappedBy = "idElemento")
    private List<Reserva> reservaList;
    @JoinColumn(name = "ID_TIPO", referencedColumnName = "ID_TIPO_RECURSO")
    @ManyToOne
    private TipoRecurso idTipo;
    @JoinColumn(name = "ID_ESTADO", referencedColumnName = "ID_ESTADO")
    @ManyToOne
    private EstadoRecurso idEstado;
    @OneToMany(mappedBy = "idElemento")
    private List<Prestamo> prestamoList;

    public Recurso() {
    }

    public Recurso(BigDecimal idRecurso) {
        this.idRecurso = idRecurso;
    }

    public BigDecimal getIdRecurso() {
        return idRecurso;
    }

    public void setIdRecurso(BigDecimal idRecurso) {
        this.idRecurso = idRecurso;
    }

    public String getDescRecurso() {
        return descRecurso;
    }

    public void setDescRecurso(String descRecurso) {
        this.descRecurso = descRecurso;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    @XmlTransient
    public List<Reserva> getReservaList() {
        return reservaList;
    }

    public void setReservaList(List<Reserva> reservaList) {
        this.reservaList = reservaList;
    }

    public TipoRecurso getIdTipo() {
        return idTipo;
    }

    public void setIdTipo(TipoRecurso idTipo) {
        this.idTipo = idTipo;
    }

    public EstadoRecurso getIdEstado() {
        return idEstado;
    }

    public void setIdEstado(EstadoRecurso idEstado) {
        this.idEstado = idEstado;
    }

    @XmlTransient
    public List<Prestamo> getPrestamoList() {
        return prestamoList;
    }

    public void setPrestamoList(List<Prestamo> prestamoList) {
        this.prestamoList = prestamoList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idRecurso != null ? idRecurso.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Recurso)) {
            return false;
        }
        Recurso other = (Recurso) object;
        if ((this.idRecurso == null && other.idRecurso != null) || (this.idRecurso != null && !this.idRecurso.equals(other.idRecurso))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.recursos.entidades.Recurso[ idRecurso=" + idRecurso + " ]";
    }
    
}
